package com.zhl.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

/*
菜品操作类：负责对菜品进行上架、浏览的操作
牛肉面", 18.8, "精致的牛肉面，味道鲜美"
"鸡蛋灌饼", 2.5, "香脆的鸡蛋灌饼，营养丰富"
"豆汁焖面", 19.9, "浓郁的豆汁，焖面层次丰富"
"豆腐脑", 12.8, "香嫩的豆腐脑，口感细腻"
"豆角炒饭", 15.9, "清淡的豆角，配上鲜美的辣椒"
"牛排", 16.8, "嫩滑的牛排，味道鲜美"
 */
public class FoodOperate {

    //1.定义一个ArrayList集合，用于存储菜品信息
    private ArrayList<Food> foods = new ArrayList<Food>();


    //2.开发上架菜品的方法  注：面向对象的代码都不加 static 关键字
    public void addFood() {   //添加食物
        //3.创建一个菜品对象,封装上架的菜品信息
        Food f = new Food();

        //4.录入菜品的名称、价格、描述
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入菜品名称：");
        f.setName(sc.next());

        System.out.println("请输入菜品价格：");
        f.setPrice(sc.nextDouble());

        System.out.println("请输入菜品描述：");
        f.setDesc(sc.next());

        //5.将菜品对象添加到ArrayList集合中
        foods.add(f);
        System.out.println("菜品上架成功！");


    }
    //6.展示菜品信息
    public void showFood() {
        if (foods.size() == 0){   //判断ArrayList集合是否为空
            System.out.println("菜品库存为空！");
            return;
            }

        for (int i = 0; i < foods.size(); i++){
            Food f = foods.get(i);
            System.out.println("菜品名称：" + f.getName());
            System.out.println("菜品价格：" + f.getPrice());
            System.out.println("菜品描述：" + f.getDesc());
            System.out.println("------------------------");
        }

    }
        //7.负责显示操作界面
    public void start(){

        while (true) {

            System.out.println("请选择功能:");
            System.out.println("1.上架菜品");
            System.out.println("2.浏览菜品");
            System.out.println("3.退出系统");
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入选项：");

            switch(sc.next()){
                case "1":
                    addFood();
                    break;
                case "2":
                    showFood();
                    break;
                case "3":
                    System.out.println("欢迎下次光临！");
                    return;   //break只会推出当前的switch，不会退出整个循环,应该使用return退出整个方法。
                default:
                    System.out.println("输入错误，请重新输入！");
            }
        }
    }

}
